<?php

namespace app\common\model;

/**
 * [寺院表]
 * @author [C。]
 * @return html
 */
class Company extends Base
{
    protected $name = 'company';

    /**
     * 根据搜索条件获取寺院列表信息
     */
    public function getlist($map,$from = 0, $size = 5,$field = 'id,info,info1,comname,province,city,qu,compic,phone,addtime,states,remarks,contract,fahao,focus,ispo,update_time,istop,istop1,jieyuan_isshow,read_num,bj_music,alllog',$order = ['ispo'=>'desc','id' => 'desc'])
    {
//        $join = [
//            ['app_manager am','am.id = c.manager_id'],
//        ];
        $result =  $this->field($field)
//            ->alias('c')
//            ->join($join)
            ->where($map)
            ->order($order)
            ->limit($from, $size)
            ->select();

        return $result;
    }

    /**
     * 搜索获取寺院列表总数
     * @param array $param
     */
    public function getCount($map) {
//        $join = [
//            ['app_manager am','am.id = c.manager_id'],
//        ];
        return $this
//            ->alias('c')
//            ->join($join)
            ->where($map)
            ->count();
    }
    /**
     * 根据搜索条件获取寺院列表信息
     */
    public function getCompanyByConditon($map,$field = '*')
    {
        $order = ['id' => 'desc'];

        $result =  $this->field($field)
            ->where($map)
            ->order($order)
            ->select();

        return $result;
    }
    /**
     * 根据搜索条件获取寺院列表信息
     * type 1首页 2古刹列表
     */
    public function getCompanyByConditons($map,$from = 0, $size = 5,$fields = 'id,comname,compic,province,city,qu,lng,lat,focus,ispo,istop,info,info1,istop,istop1',$type = 1)
    {
        if($type == 1){
            $order = ['istop'=>'desc','info'=>'desc','ispo'=>'desc','id'=>'desc'];
        }else{
            $order = ['istop1'=>'desc','info1'=>'desc','ispo'=>'desc','id'=>'desc'];
        }

        $result =  $this->field($fields)
            ->where($map)
            ->order($order)
            ->limit($from, $size)
            ->select();

        return $result;
    }
    /**
     * 根据搜索条件获取寺院列表信息
     */
    public function getCompanyCount($map) {
        $result = $this->where($map)->count();
        return $result;
    }
    /**
     * 根据搜索条件获取寺院列表信息
     */
    public function edit_readnum($map) {
        $result = $this->where($map)->setInc('read_num',1);
        return $result;
    }
    public function edit()
    {
        $result =  $this->where('id','>',0)->update(['manager_id' => 20]);
        return 1;
    }
    /**
     * 根据搜索条件获取寺院列表信息
     */
    public function getCount1($map)
    {
        $order = ['id' => 'desc'];

        $result =  $this
            ->where($map)
            ->order($order)
            ->count();

        return $result;
    }
    /**
     * 根据搜索条件获取寺院列表信息
     * type 1首页 2古刹列表
     */
    public function getlist1($map,$from = 0, $size = 5,$fields = '*',$order=[])
    {
//        $order = ['istop1'=>'desc','info1'=>'desc','ispo'=>'desc','id'=>'desc'];

        $result =  $this->field($fields)
            ->where($map)
            ->order($order)
            ->limit($from, $size)
            ->select();

        return $result;
    }
}